package com.ziyun.pop.modules.storeMaterials.service.impl;

import io.renren.common.utils.R;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.ziyun.pop.modules.storeMaterials.dao.StoreStockMaterialDao;
import com.ziyun.pop.modules.storeMaterials.entity.StoreStockMaterialEntity;
import com.ziyun.pop.modules.storeMaterials.service.StoreStockMaterialService;

/**
 * 门店库存明细表
 *
 * @author guizhao
 * @email 296588519@qq.com
 * @date 2018-10-08 11:31:20
 */
@Service("storeStockMaterialService")
public class StoreStockMaterialServiceImpl extends ServiceImpl<StoreStockMaterialDao, StoreStockMaterialEntity> implements StoreStockMaterialService {

    @Override
    public StoreStockMaterialEntity getStockMaterial(String materialId, Long sellerId) {
        return baseMapper.getStockMaterial(materialId,sellerId);
    }

    @Override
    public Integer updateMaterialInfo(BigDecimal quantity,BigDecimal money,String materialId,Integer stockID) {
        return baseMapper.updateMaterialInfo(quantity,money,materialId,stockID);
    }

    @Override
    public Integer updateMaterialWarehouse(BigDecimal StockQuantity,BigDecimal quantity, String materialId,Integer stockId, Integer direction, Date updateTime,BigDecimal price) {
        return baseMapper.updateMaterialWarhouse(StockQuantity,quantity,materialId,stockId,direction,updateTime,price);
    }

	@Override
	public Integer updateMaterialWarehouse2(BigDecimal quantity,Date date,BigDecimal moneys,String materialId,Integer stockId) {
		return baseMapper.updateMaterialWarhouse2(quantity,date,moneys,materialId,stockId);
	}

	@Override
    public BigDecimal getMaterialQuantity(String materialId,Integer stockId) {
        return baseMapper.getMaterialQuantityByMaterialID(materialId,stockId);
    }

    @Override
    public Integer updateQuantityByMaterialId(String materialId, BigDecimal quantity, BigDecimal price,Integer stockId) {
        return baseMapper.updateQuantityByMaterialId(materialId,quantity,price,stockId);
    }

    @Override
    public R selectCostByMaterialId(String materialId) {
        List<StoreStockMaterialEntity> list = baseMapper.getCostByMaterialId(materialId);
        if(list.size() == 0){
            return R.error("请维护耗材Id"+materialId+"的总价");
        }
        return R.ok();
    }

    @Override
    public BigDecimal getMaterialQuantityByStockID(String materialId, Integer stockId) {
        return baseMapper.getMaterialQuantityByStockId(materialId,stockId);
    }

    @Override
    public BigDecimal getCost(String materialId, Integer stockId) {
        return baseMapper.getCostByMaterialIdAndStockId(materialId,stockId);
    }

    /**
     * 盘存修改库存数量和金额
     * @param materialQuantity
     * @param stockId
     * @param materialId
     * @return
     */
    @Override
    public Integer updateTIStoreStock(BigDecimal materialQuantity, Integer stockId, String materialId) {
        return this.baseMapper.updateTIStoreStock(materialQuantity,stockId,materialId);
    }
}
